Skip to content

perf(agc): deliver end-of-pipe interrupts after their work without draining - #409

Merged
boykopovar merged 1 commit into
boykopovar:mainfrom
oneandonlydean:perf/agc-defer-eop-interrupts
Oct 3, 2026
Merged

boykopovar merged 1 commit into
boykopovar:mainfrom
oneandonlydean:perf/agc-defer-eop-interrupts

Conversation

@oneandonlydean

Copy link
Copy Markdown
Collaborator

What

A RELEASE_MEM with an interrupt select (an end-of-pipe interrupt) drained the device: the queue worker submitted everything recorded, waited for the GPU, then stored the label on the CPU and delivered the interrupt. PPSA21564 issues about 300 of these per frame, so the graphics worker and the GPU took turns. In a profile of my integration branch at the title screen, RELEASE_MEM handling took about 2.3 s of every 10 s of the graphics worker, almost all of it waiting.

This PR keeps the packet's meaning (the interrupt reaches the queue's event once the work before it completed and its label landed) without the CPU wait:

  • The label is recorded like any other label: stored by the GPU behind the recorded work (WriteLabelOnGpu), or kept as a completion action behind pending write-backs (reasons 5 and 6), exactly as for a RELEASE_MEM without an interrupt. With nothing recorded (reason 1) it is stored on the CPU and the interrupt is delivered at once, as before.
  • The delivery becomes a completion action of the batch holding the work before the packet: the open batch, or the newest in-flight batch when none is open (Recorder::AfterRecordedWork, VulkanDevice::AfterRecordedWork). It is appended after that batch's earlier completions, so a label kept as a completion action lands first. It is counted with the completion labels, so idle queue workers and WAIT_REG_MEM pollers reap its batch; it also starts the label flush deadline, like a pending label.
  • When draws or dispatches were recorded since the last submit, the batch is submitted at once, so the interrupt follows exactly the work before it.
  • When nothing but labels was recorded since the last submit (back-to-back releases separated only by waits, events and labels, about 80% of them in PPSA21564), the batch holding the label stores stays open instead of going out as a batch of its own. It is submitted with the next work, at the label flush deadline (1 ms by default, checked between packets and while a WAIT_REG_MEM polls), at a wait on one of its labels, at a flip or at the end of the submission, like any other pending label.
  • A label WriteLabelOnGpu refuses (reasons 2 to 4), a label that does not decode, and APS5_DRAIN_ALL still drain as before.

Ordering guarantees:

  • Labels are still written by the GPU in record order, in the same command stream as every other label; nothing is moved to a CPU store out of order.
  • An interrupt is delivered only after the batch holding the work before it completed and after that batch's earlier completion stores ran, so it never arrives early. It can arrive later than before, by at most the flush deadline plus the work recorded into the same batch in the meantime.
  • Latency stays bounded because the action counts as a pending label: the deadline, waits on its labels, flips and the end of a submission all submit the open batch. A WAIT_REG_MEM for something the CPU does on the interrupt cannot hold the batch back either: its poll submits the batch once the deadline passed.

Two variants I tried first and dropped, for context:

  • leaving the batch open even with draws recorded, so the delivery also waited for the packets recorded after the RELEASE_MEM: PPSA21564's intro presented a garbage frame in 5 of 25 runs;
  • turning label-only end-of-pipe labels into CPU stores at the previous batch's reap: later GPU-stored labels could land before them, and a profiled PPSA21564 run died on a corrupt command packet.

Tests:

  • testEndOfPipeLabelsWithoutWork (agc_driver_tests): two back-to-back end-of-pipe labels with no work before them land, satisfy a WAIT_REG_MEM on the compute queue, and raise both interrupts. Without a device (CI) this covers the CPU path only.
  • afterRecordedWorkTests (agc_driver_recorder_tests, needs a Vulkan device, run by hand like the rest of that binary): an idle recorder refuses the action; an action behind the open batch is pending and starts the label flush deadline; actions behind the open batch, behind a completion label and behind an in-flight batch run once each, in order, only when their batch is reaped, and after the completion label recorded ahead of them landed.

Tested

  • Linux (CachyOS, GCC 16), RTX 4090: ctest 125/125 pass, including testEndOfPipeLabelsWithoutWork. agc_driver_recorder_tests by hand: passes, including afterRecordedWorkTests.
  • Without the change: afterRecordedWorkTests does not build (it tests the new Recorder::AfterRecordedWork). testEndOfPipeLabelsWithoutWork has no device in agc_driver_tests, so it takes the CPU path and also passes on main; it guards the label-only case that the batch deferral changes.
  • PPSA21564: the same change (as three commits plus two debug switches, dropped here) has been on my integration branch for many runs of my visual regression check (intro, title, menu and a level), passing them with the shimmer check clean.
    • Drains: RELEASE_MEM handling went from about 2.3 s to about 0.45 s per 10 s of the graphics worker at the title.
    • Batches: about 85k per 10 s at the title before the label-only batches stayed open, about 70k of them holding nothing but label stores; about 18k after.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none. fix(agc): depth fast clears through the HTILE metadata #374 adds lines at the same spot in preparePacketMemory, so whichever lands second needs a small rebase.
  • AI-assisted: yes

…aining

A RELEASE_MEM with an interrupt select drained the device: the queue
worker submitted everything recorded and waited for the GPU before it
stored the label and delivered the interrupt. PPSA21564 issues about 300
of them per frame, so the worker and the GPU took turns.

The label is now recorded like any other (on the GPU behind the work, or
as a completion action behind pending write-backs), and the delivery
becomes a completion action of the batch holding the work before the
packet (Recorder::AfterRecordedWork, after the batch's earlier
completions). It is counted with the completion labels, so idle workers
and pollers reap it, and it starts the label flush deadline. With draws
or dispatches recorded since the last submit the batch is submitted at
once. A batch holding only label stores stays open and goes out with the
next work, at the label flush deadline, at a wait, at a flip or at the
end of the submission, like any other pending label. A label the GPU
cannot store, or one that does not decode, still drains.

The interrupt so never arrives before the work ahead of it completed and
its label landed; it can only arrive later, by at most the flush
deadline plus the work recorded into the same batch.
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#419 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp L6, L19
#425 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp L6, L19
#426 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp L6, L19

@boykopovar
boykopovar merged commit c394893 into boykopovar:main Oct 3, 2026
3 checks passed
@oneandonlydean
oneandonlydean deleted the perf/agc-defer-eop-interrupts branch October 3, 2026 07:02
oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 3, 2026
…oykopovar#304 boykopovar#305 boykopovar#306 boykopovar#322 boykopovar#409 boykopovar#416, boykopovar#276 boykopovar#277 boykopovar#275 boykopovar#307, shader ops boykopovar#226 boykopovar#255 boykopovar#260 boykopovar#280 boykopovar#308 boykopovar#309 boykopovar#311 boykopovar#318 boykopovar#320 boykopovar#324 boykopovar#326 boykopovar#379 boykopovar#384 boykopovar#399, boykopovar#261, kernel boykopovar#335 boykopovar#341 boykopovar#349 boykopovar#355, libs boykopovar#227 boykopovar#244 boykopovar#245 boykopovar#273 boykopovar#274 boykopovar#279 boykopovar#286 boykopovar#287 boykopovar#289 boykopovar#296 boykopovar#300 boykopovar#328 boykopovar#358 boykopovar#402) into astrobot

Where our PR merged in a revised form, main's version is taken; where
astrobot carries the same work plus later local commits, astrobot's code
stays and main's additions appear once.

Conflicts:
- AvPlayer (Export.cpp both libs, include/AvPlayer.hpp, src/Player.cpp,
  src/Source.cpp, AvPlayerLibrary.cmake, CMakeLists.txt, SceTypes.hpp,
  tests/GuestAvPlayer.cpp): main's boykopovar#307 (our reviewed squash, which carries
  9c8e7fd e9ea5c8 adcede3 fb4eeb9 953057c ac456ee). It links the
  shared ffmpeg-core target, so astrobot's second FFmpeg build goes:
  3rdparty/FFmpeg submodule, core/libs/FFmpeg.cmake and src/Exports.cpp.
- libScePngEnc: main's boykopovar#227 (supersedes OverkillLabs' encoder).
- libScePad Export.cpp: main's boykopovar#287 tilt correction (supersedes 49d45f5).
- libSceAudioPropagation Export.cpp: astrobot's object model, which
  defines every function boykopovar#289 declares as a stub.
- libSceSaveData.native Export.cpp: both (SaveDataHoldWrites and boykopovar#289's
  unknown exports).
- VideoOutDriver.cpp: astrobot's (2546bd1 counters around boykopovar#416's
  lastFlipVblank store, same value). tests/Flip.cpp: boykopovar#416's pacing test and
  boykopovar#417's after-GPU test both kept.
- boykopovar#278 files (DisplayFormat, VulkanDevice, GpuColorTransfer,
  ResidentPresent, agc CMakeLists): main's comment-free boykopovar#278 plus
  astrobot's P5 present-direct (b29728d), which removed DetileImage,
  ResidentPresent.hpp and the recorder-test hook; the resident present test
  stays its own executable.
- VulkanDevice.cpp/.hpp: astrobot's GDS, local memory probe, sample dumps
  and P5 code; boykopovar#303/boykopovar#409 comments as main has them; main's shader clock
  (boykopovar#324) and DepthSurface-free includes.
- RequestSerializer.cpp: version stays 8 (6 mesh passthrough, 7
  nonConstantImageOffsets, 8 astrobot's later field). boykopovar#303's auto-merged
  second write and read of nonConstantImageOffsets removed.
- SpirvEmitter.hpp, SpirvEmitterState.hpp, Recompiler.hpp/.cpp, StageIO.hpp,
  SpirvOptimizer.cpp, InstructionTranslator.cpp, ShaderReplay.cpp: local
  fields kept, boykopovar#303/boykopovar#305 comments as main has them.
- SpirvAluEmitterMath.cpp: v_readlane keeps the split-wave path and takes
  boykopovar#322's wrap at the wave size for the others.
- SpirvEmitter.cpp: astrobot's single-lane layout check.
- SpirvFlowEmitter.cpp: boykopovar#304 as merged (the second lane emits a shared
  value itself when the first lane defined nothing).
- SpirvImageEmitter.cpp: main's Offset operand placed before MinLod.
- boykopovar#304: main's WaveUniformValues (SpirvAnalysis.cpp) replaces astrobot's
  copy in SpirvWaveExchange.cpp.
- Recorder.hpp/.cpp, Draw.hpp, Graphics Draw.cpp, ShaderResources.cpp:
  astrobot's boykopovar#276/boykopovar#277 with its later snapshot work (per-use budgets,
  stale-snapshot refresh, profile counters, boykopovar#410, boykopovar#424, fan GS); boykopovar#409/boykopovar#306
  comments as main has them.
- PacketMemory.cpp: boykopovar#409 as merged plus astrobot's two opt-outs.
- tests: ShaderMemory.cpp takes boykopovar#303's and boykopovar#304's new tests; Recorder.cpp
  takes boykopovar#409's afterRecordedWorkTests and drops main's copies of the
  boykopovar#276/boykopovar#277 tests astrobot already has; Structurizer.cpp keeps boykopovar#413's case.

boykopovar#143 (NGG passthrough) stays as on astrobot: upstream did not touch its
files since the boykopovar#258 revert.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants